<template>
  <div class="aplayer-box"><aplayer ref="audio" :autoplay="true" :music="music" /></div>
</template>

<script>
import Aplayer from 'vue-aplayer';

export default {
  components: {
    Aplayer
  },
  props: {
    file: {
      type: Object,
      required: true
    },
    preview: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      music: {
        src: this.file.playurl,
        title: this.file.filename,
        pic: this.file.cover_url,
        artist: '音频'
      }
    };
  },
  watch: {
    preview(val) {
      if (val === false) {
        this.$refs.audio.pause();
      } else {
        this.$refs.audio.play();
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.aplayer-box {
  width: 100%;

  ::v-deep.aplayer-pic .aplayer-pause {
    width: 26px;
    height: 26px;
    border: 2px solid #fff;
    bottom: 50%;
    right: 50%;
    margin: 0 -15px -15px 0;
  }

  ::v-deep.aplayer-pic .aplayer-pause .aplayer-icon-pause {
    position: absolute;
    top: 3px;
    left: 4px;
    height: 20px;
    width: 20px;
  }
}
</style>
